package face.pay.common.enterprise.service.impl;

import face.pay.common.enterprise.service.IEnterpriseBaseService;
import face.pay.dao.EnterpriseInfoDao;
import face.pay.dao.OemInfoDao;
import face.pay.entity.EnterpriseInfo;
import face.pay.entity.OemInfo;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: zkj
 * @Date: 2019/7/11 09:11
 * @Description:商户 公共服务层
 * 包含 商户基本信息编辑
 *
 */
@Service
@Slf4j
public class EnterpriseBaseServiceImpl implements IEnterpriseBaseService {

    @Autowired
    private EnterpriseInfoDao enterpriseInfoDao;

    @Autowired
    private OemInfoDao oemInfoDao;

    @Override
    public EnterpriseInfo getInfoByUserId(Integer userId) {


        EnterpriseInfo enterpriseInfo =  enterpriseInfoDao.queryByUserId(userId);

        OemInfo oemInfo = this.oemInfoDao.getOemInfoById(enterpriseInfo.getOemId());

        String callBackRrl = oemInfo.getAliCallBackUrl();

        if(StringUtils.isNotBlank(callBackRrl)){

            String aliCallBackUrl = callBackRrl+"?state="+enterpriseInfo.getUserId();

            enterpriseInfo.setAliCallBackUrl(aliCallBackUrl);
        }

        return enterpriseInfo;

    }

    @Override
    public ResultMessage modifyInfo(EnterpriseInfo enterpriseInfo, UserInfo loginUser) {

        enterpriseInfoDao.update(enterpriseInfo);

        return  ResultMessage.createSuccess();
    }


}
